package cn.anlucky.apiadmin.utils;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public class DateTimeUtil {
    /**
     * 日期格式化yyyy-MM-dd HH:mm:ss
     *
     * @param date
     * @return
     */
    public static String getDateTimeFormat(Date date) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
    }

    /**
     * 时间格式化
     *
     * @param date
     * @return
     */
    public static Date getDateTimeFormat(String date) {
        try {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
        } catch (Exception e) {
           throw new RuntimeException(e.getMessage());
        }
    }

    /**
     * 取当前时间到今天晚上12点的毫秒数
     * @return
     */
    public static Long getTomorrowTime(){
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime endOfDay = now.toLocalDate().atTime(23, 59, 59);

        long millisecondsUntilEndOfDay = now.until(endOfDay, ChronoUnit.MILLIS);

        return millisecondsUntilEndOfDay;
    }





}
